package Thread;

public class Demo4 {
    public static void main(String[] args) {
        /*1. 创建新的类,实现Runnable
             但是类的名字是匿名的
          2. 创建了这个新类的实例.(一次性)
          3. 重写了run方法
         */
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    System.out.println("hello thread");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        });

        t.start();

        while (true) {
            System.out.println("hello main");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
